﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DMEditor
{
    public partial class frmStartup : Form
    {
        public frmStartup()
        {
            InitializeComponent();
        }

        private void frmStartup_Load(object sender, EventArgs e)
        {
            // Load our soundsets 
            Program.settings.soundsets[0].Load("soundsets/stock.xml");
            Program.settings.soundsets[1].Load("soundsets/bluejay.xml");
            Program.settings.soundsets[2].Load("soundsets/redbox.xml");


            Program.MainForm.reloadSoundset();

            for (int i = 0; i < Program.module.ports.Count; ++i)
            {
                ddlMIDIPorts.Items.Add(Program.module.ports[i]);
            }

            ddlMIDIPorts.SelectedIndex = Program.module.currentPort;
        }

        private void btnNewModule_Click(object sender, EventArgs e)
        {
            if (rdoSoundsetStock.Checked) Program.settings.currentSoundset = 0;
            else Program.settings.currentSoundset = 1;

            Program.MainForm.reloadSoundset();
            Program.settings.setDefaults();

            OpenMIDIPort();

            Program.MainForm.setTitle("New Module");
            Program.MainForm.Show(); 
            this.Hide();
            
        }

        private void btnOpenModule_Click(object sender, EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();
            dlg.Filter = "DM10 Modules|*.dmm";
            dlg.DefaultExt = ".dmm";
            DialogResult res = dlg.ShowDialog();

            if (res == System.Windows.Forms.DialogResult.OK)
            {
                Program.settings.LoadModule(dlg.FileName);

            OpenMIDIPort();

            Program.MainForm.setTitle(dlg.FileName);

            Program.MainForm.Show();
            Program.MainForm.finishLoad(); 
            this.Hide();
            }
        }

        

        private void OpenMIDIPort()
        {
            Program.module.currentPort = ddlMIDIPorts.SelectedIndex;
            Program.module.Open(ddlMIDIPorts.SelectedIndex);
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

    }
}
